package CI;

import java.util.HashMap;

public class Environment {
	private Environment _parent;
	private HashMap<String,Object> _frame;
	
	public Environment(Environment parent) {
		_parent = parent;
		_frame = new HashMap<String,Object>();
		addVariable("true", Boolean.TRUE);
		addVariable("false", Boolean.FALSE);
	}
	public void addVariable(String name, Object value) {
		_frame.put(name,value);
	}
	public Object lookupVariable(String name) throws EvalError {
		if (_frame.containsKey(name)) {
			return _frame.get(name);
		}
		else if (_parent != null) {
			return _parent.lookupVariable(name);
		}
		else {
			throw new EvalError("Undefined name " + name);
		}
	}
}
